package com.comp437.uno.view.login;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.comp437.uno.model.Model;
import com.comp437.uno.view.playroomlist.PlayRoomListView;
import com.example.comp437uno.R;

	public class SignUp extends Activity{
	private Button bt_SignUp = null;
	private EditText userName,password,passwordAgain;
	private RadioButton rb_male,rb_female;
	private Model model;
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        model = Model.getModel();
	        setContentView(R.layout.signup);
	        bt_SignUp = (Button) findViewById(R.id.button_signup_signup);
	        userName = (EditText) findViewById(R.id.edittext_signup_username);
	        password = (EditText) findViewById(R.id.edittext_signup_password);
	        passwordAgain = (EditText) findViewById(R.id.edittext_signup_password_again);
	        rb_male = (RadioButton) findViewById(R.id.radiobutton_signup_male);
	        rb_female = (RadioButton) findViewById(R.id.radiobutton_signup_female);
	        bt_SignUp.setOnClickListener(new Mybt_SignUpListener());
	 }
	 
	 
	 class Mybt_SignUpListener implements android.view.View.OnClickListener {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				String username, pw,pw2;
				boolean gender=false;;
				username=userName.getText().toString();
				pw =  password.getText().toString();
				pw2 =  passwordAgain.getText().toString();
				
				
				if(username==""||username.contains(" "))
					model.showToast(SignUp.this, "Please Input UserName without \' \'");
				else if(pw == ""||pw2 == "")
					model.showToast(SignUp.this, "The password should not be blank");
				else if(!pw.equals(pw2))
					model.showToast(SignUp.this, "The two password should be the same");
				else if(rb_male.isChecked()&&rb_female.isChecked())
					{if(rb_male.isChecked())
						gender = true;
					else 
						gender = false;
					model.signUp(username,pw,gender);
					}
				else
					model.showToast(SignUp.this, "Please Select your gender");

			}
		}
	 public void SignUpSuccessful(String userid){
		
			if(userid!=null){
				
				if(!userid.equals("")){
			
					Intent intent=new Intent();
					intent.putExtra("username", userid);
					intent.setClass(SignUp.this, PlayRoomListView.class);
					SignUp.this.startActivity(intent);
				}else{
					model.showToast(SignUp.this, "Wrong Username ");
				}
			}else
				model.showToast(SignUp.this,"reply null");
	 }
}
